package com.sixmac.utils;

import java.net.URLEncoder;
import java.util.HashMap;

public class SendSMSDemo {

    public static boolean sendMessage(String mobile, String code) {
        String address = "120.77.15.48";//远程地址：不带http://
        int port = 7862;//远程端口
        String account = "833013";//账户
        String token = "hxDSiF";//pwd
        String body = "【视得】您的验证码为：" + code;//短信内容
        String extno = "10690013";//接入号
        KXTSmsSDK kxtsms = new KXTSmsSDK();
        kxtsms.init(address, port, account, token);
        try {
            body = URLEncoder.encode(body, "UTF-8");//URL编码 UTF-8方式
        } catch (Exception e) {
            e.printStackTrace();
        }
        String result = kxtsms.send(mobile, body, extno);
        HashMap<String, Object> hashMap = CommonUtils.xmlToMap(result);
        if (null != hashMap) {
            String returnstatus = (String) hashMap.get("returnstatus");
            if ("Success".equals(returnstatus)) {
                System.out.println("发送验证码成功。。。");
                return true;
            } else {
                System.out.println("发送验证码失败。。。");
                return false;
            }
        } else {
            System.out.println("发送验证码失败。。。");
            return false;
        }
    }

    public static void main(String[] args) {
        sendMessage("18717101121", "885695");
    }
}
